/*
 * Copyright 2016 Yan Zhenjie
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mingmen.canting.caigourenyuan;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.mingmen.canting.R;
import com.mingmen.canting.base.BaseBean;
import com.mingmen.canting.http.callback.StringCallback;
import com.mingmen.canting.httpconfig.HttpResponse;
import com.mingmen.canting.util.GsonUtil;
import com.mingmen.canting.util.MyStringUtils;
import com.mingmen.canting.util.SharePreferenceUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;
import okhttp3.Call;
import okhttp3.Response;


/**
 * <p>
 * ListView形式的侧滑菜单，支持横向和竖向的。
 * </p>
 * Created by Yan Zhenjie on 2016/7/27.
 */
public class TuiHuoDialogActivity extends Activity {
    @BindView(R.id.img_return)
    ImageView imgReturn;
    @BindView(R.id.layout_close)
    LinearLayout layoutClose;
    String string;
    @BindView(R.id.btn_no)
    Button btn_no;
    @BindView(R.id.btn_yes)
    Button btn_yes;
    String billId;
    String token;
    String supplierId;
    String cancelReason;
    String pictureList;
    String getBillDetailIds;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tuihuo_dialog);
        ButterKnife.bind(this);
        billId = getIntent().getStringExtra("billId");
        supplierId = getIntent().getStringExtra("supplierId");
        cancelReason = getIntent().getStringExtra("cancelReason");
        pictureList = getIntent().getStringExtra("pictureList");
        token = (String) SharePreferenceUtil.get(this, "token", "");
        Log.d("pictureList", pictureList.toString());
        getBillDetailIds = getIntent().getStringExtra("getBillDetailIds");
        initData();
        bindView();

    }

    private void bindView() {

    }


    private void initData() {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

    @OnClick({R.id.img_return, R.id.layout_close, R.id.btn_no, R.id.btn_yes})
    public void onViewClicked(View view) {
        Intent intent;
        switch (view.getId()) {

            case R.id.img_return:
            case R.id.layout_close:
                finish();

                break;
            case R.id.btn_no:


                HttpResponse.cancelOrder(token, cancelReason, pictureList, getBillDetailIds, new StringCallback(this) {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        BaseBean baseBean = GsonUtil.GsonToBean(s, BaseBean.class);
                        if (baseBean.getCode() == 0) {
                            EventBus.getDefault().post(4);
                            EventBus.getDefault().post(3);
                            EventBus.getDefault().post(2);

                            finish();
                        }
                        Toast.makeText(TuiHuoDialogActivity.this, baseBean.getMessage() + "", Toast.LENGTH_SHORT).show();
                    }
                });
                break;
            case R.id.btn_yes:
                intent = new Intent(TuiHuoDialogActivity.this, ChongXinGongYingActivity.class);
                intent.putExtra("billId", billId);
                intent.putExtra("cancelReason", cancelReason);
                intent.putExtra("pictureList",pictureList);
                startActivity(intent);
                finish();
                break;
        }
    }


}